using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class BasePlayer : MonoBehaviour
{
    public AudioClip[] JumpSounds;
    public Vector2 screenSize;
    public float Force = 10;
    public Rigidbody2D Rigidbody;
    public Vector2 Direc;
    public Basket CurrentBasket;

    private AudioSource audioSource;
    

    public void Awake() 
    {
        audioSource = GetComponent<AudioSource>();
    }

    public void Jump() {
        if (!TimeManager.isGameOver)
        {
            if (!CurrentBasket.flip_x) 
            {
                Direc.x = -Mathf.Abs(Direc.x);
            } 
            else
            {
                Direc.x = Mathf.Abs(Direc.x);
            }
            Rigidbody. velocity = Force * Direc;
            audioSource.PlayOneShot(JumpSounds[Random.Range(0, JumpSounds.Length)]);
        }
   }

    public void ChangeSide() {
        if (transform.position.x > screenSize.x) {
            transform.position = new Vector2(-screenSize.x, transform.position.y);
        }
        if (transform.position.x < -screenSize.x)
        {
            transform.position = new Vector2(screenSize.x, transform.position.y);
        }
    }
}
